<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :show="show" @click-show="show = !show" :fixed="true" :back="true" color="#fff" :title="title"></uni-navbar></view>

		<view class="filter-box" v-if="show">
			<view class="form-box">
				<u-form ref="uForm">
					<u-form-item class="form-item" label="标题">
						<u-input v-model="ycxsHstRoom.roomName" type="text" placeholder="请输入标题" />
					</u-form-item>
				</u-form>
			</view>
			<view class="fiexd-btm">
				<view class="flex-box">
					<u-button class="form-btn" type="default" @click="resert">清除</u-button>
					<u-button class="form-btn" type="error" @click="filter">确定</u-button>
				</view>
			</view>
		</view>

		<view class="search-view">
			<u-search class="search-input" shape="square" bg-color="#fff" v-model="ycxsHstRoom.roomName" :show-filter="true" @search="search" @custom="show = !show"></u-search>
		</view>
		<u-tabs class="uTabs" :list="tabsList" :current="tabsCurrent" @change="tabsChange" :is-scroll="false"></u-tabs>

		<view class="list-box" :style="{ background: loading == 'nodata' ? 'none' : '#fff' }">
			<view class="list-info_01" v-for="(item, index) of negotiateList" :key="item.id" @click="navTo(item)">
				<view class="info-title">{{ item.roomName }}</view>
				<view class="info-btm">
					<view class="btm-left clamp">
						<text class="left-name">{{ item.createByName }}</text>
						<text class="left-time">{{ item.createTime }}</text>
					</view>
					<view class="btm-right">
						<view class="right-type" :style="'color:' + colorMap[item.nodeStatus]">{{ statusMap[item.nodeStatus] }}</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="loading" />
		</view>

		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			scrollTop: 0,
			show: false,
			tabsCurrent: 0,
			tabsList: [
				{
					name: '所有',
					value: 0
				},
				{
					name: '未开始',
					value: 1
				},
				{
					name: '进行中',
					value: 2
				},
				{
					name: '结束',
					value: 3
				}
			],
			colorMap: {
				1: '#303133',
				2: '#0099ff',
				3: '#ff9900',
				9: '#19be6b'
			},
			statusMap: {
				1: '未开始',
				2: '进行中',
				3: '结束',
				9: '撤销'
			},
			userName: '',
			nodeStatus: 0,
			title: '会议列表',
			negotiateList: [],

			ycxsHstRoom: {
				nodeStatus: '',
				status: 1,
				roomName: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad(option) {
		this.loadLogin();
		if (option && option.type) {
			this.tabsCurrent = option.type;
			this.nodeStatus = option.type;
			this.ycxsHstRoom.nodeStatus = option.type.toString();
		}
		this.loadData();
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				this.roleCodes = this.userInfo.roleCodes.join(',');
				this.userName = this.userInfo.sysUser.userName;

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}

			if (this.ycxsHstRoom.nodeStatus == '0') {
				this.ycxsHstRoom.nodeStatus = '';
			}
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				currentUserId: this.userId,
				roleCodes: this.roleCodes,
				ycxsHstRoom: this.ycxsHstRoom
			};
			this.$request('/haoshitong/myList', data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.negotiateList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.negotiateList = this.negotiateList.concat(res.data.records);
				this.loaded = true;
				if (this.negotiateList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		tabsChange(index) {
			this.tabsCurrent = index;
			this.type(this.tabsList[index].value);
		},
		filter() {
			this.show = false;
			this.loadData('refresh');
		},
		resert() {
			this.show = false;
			this.ycxsHstRoom.roomName = '';
			this.jieci = '';
			this.ycxsHstRoom.jieId = '';
			this.ycxsHstRoom.ciId = '';
			this.loadData('refresh');
		},
		search(e) {
			this.ycxsHstRoom.roomName = e;
			this.loadData('refresh');
		},
		type(e) {
			this.nodeStatus = e;
			this.ycxsHstRoom.nodeStatus = e.toString();
			this.loadData('refresh');
		},
		navTo(item) {
			if (item.nodeStatus == 2) {
				let parm = item.syncId + ',' + item.password + ',' + this.userName;
				WebviewClient.sendMessage('startVideoMeeting', parm);
			} else {
				uni.navigateTo({
					url: '/pagesB/negotiate/detail?id=' + item.id
				});
			}
		}
	}
};
</script>

<style lang="scss">
.list-box {
	padding: 0 30rpx;
	background-color: #fff;
}

.filter-box {
	position: fixed;
	left: 0;
	top: 0;
	bottom: 0;
	right: 0;
	z-index: 998;
	background-color: #fff;
}

.form-box {
	.form-item {
		@include mp-flex;
	}
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}
</style>
